package com.base.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * @author HBZ
 * @description
 * @date 2021/8/1 11:06
 */
public class Test {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        User user = new User();
        user.setName("avvv");
        Class<?> clazz = Class.forName("com.base.reflect.User");
        String field = "Name";

        boolean assignableFrom = user.getClass().isAssignableFrom(clazz);
        if (assignableFrom) {
            Method method=clazz.getMethod("getName");
            System.out.println("getReturnType---"+  method.getReturnType().getName());

            Object returnValue = method.invoke(user, null);
            if(null!=returnValue){
                System.out.println(returnValue);
            }
        }
        List<Object>a=new ArrayList<>();
        a.add(user);
        System.out.println(a.get(0).getClass());
        System.out.println(user instanceof User);
    }
}
